import java.net.Socket;
import java.io.*;

public class Obslugaklienta  extends Thread{
	private Socket socket ;
	Messageclient m ;
	private ObjectInputStream inStream; 
	private ObjectOutputStream outStream; 
	public Obslugaklienta(Socket s) throws IOException {
		socket = s ;
		System.out.println("Wykonuje konstruktor") ;
		
		System.out.println("Wykonalem konstruktor") ;
	}
	
	public Messageclient getMessage() {
		try {
			inStream = new ObjectInputStream(socket.getInputStream()); 
		} catch(Exception e) { System.out.println(e.getMessage()); }
		Messageclient m = null ;
		
		try {
			m = (Messageclient) inStream.readObject();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return m;
	}
	
	public void sendMessage(Messageclient m) { //wysylanie z serializacja 		
		try {
			outStream = new ObjectOutputStream(socket.getOutputStream()); 
		} catch(Exception e) { System.out.println(e.getMessage()); }
		
			System.out.println("Sending message to " + socket.getPort());
			try {
				outStream.writeObject(m);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	}
	
	public void run() {
		System.out.println("przetwarzam wiadomosc od klienta");		
		Messageclient m = getMessage();
		
		//tutaj przetwarzanie
		
		
		
		//tutaj przetwarzanie
		
		Messageclient odpowiedz = new Messageclient() ;
		odpowiedz.setType(1) ;
		odpowiedz.setMessage("kurwa odpowiedz") ;
		sendMessage(odpowiedz) ;
		
		}
	
	}
	